package com.itemOrder {
	import com.greensock.TweenMax;
	import com.greensock.plugins.TintPlugin;
	import com.greensock.plugins.TweenPlugin;

	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;

	TweenPlugin.activate([TintPlugin]);
	public class RadioButtonItem extends Sprite {
		private var _icon : Sprite;
		private var _field : TextField;
		private var _labelCopy : String;
		private var _currentNav : Sprite;

		public function RadioButtonItem(labelCopy : String) {
			_labelCopy = labelCopy;
			//createButton();
			this.buttonMode = true;
			this.mouseChildren = false;
			// this.addEventListener(MouseEvent.MOUSE_OVER, buttonOver);
			// this.addEventListener(MouseEvent.MOUSE_OUT, buttonOut);
			// this.addEventListener(MouseEvent.CLICK, buttonClick);
		}

		public function select() : void {
		}

		public function deselect() : void {
			trace("deselected");
		}

		public function isSelected() : Boolean {
			return false;
		}

		public function buttonOver(e : MouseEvent) : void {
			var navItem : Sprite = e.target as Sprite;
			if (navItem != _currentNav) {
				TweenMax.to(e.target, .5, {tint:0x787879});
			}
		}

		public function buttonOut(e : MouseEvent) : void {
			var navItem : Sprite = e.target as Sprite;
			if (navItem != _currentNav) {
				TweenMax.to(e.target, .2, {tint:null});
			}
		}

		public function buttonClick(e : MouseEvent) : void {
			var navItem : Sprite = e.target as Sprite;
			if (_currentNav != null) {
				TweenMax.to(_currentNav, .3, {tint:null});
			}
			TweenMax.to(e.target, .3, {tint:0x000000});
			_currentNav = navItem;
		}

		private function createButton() : void {
			var format : TextFormat = new TextFormat();
			format.font = new Font1().fontName;
			format.size = 15;
			format.letterSpacing = 1;
			format.align = TextFormatAlign.LEFT;

			_field = new TextField();
			_field.mouseEnabled = false;
			_field.textColor = 0x000000;
			_field.defaultTextFormat = format;
			_field.antiAliasType = AntiAliasType.NORMAL;
			_field.autoSize = TextFieldAutoSize.LEFT;
			_field.text = _labelCopy;
			_field.x = 15;
			addChild(_field);

			_icon = new Sprite();
			_icon.graphics.beginFill(0xCCCCCC);
			_icon.graphics.drawCircle(0, 0, 6);
			_icon.graphics.endFill();
			_icon.x = 6;
			_icon.y = Math.round(_field.height / 2);
			addChild(_icon);
		}
	}
}
